<%@ Page language="c#"%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%
    string id = Request.QueryString["id"] as string; 
    if (id == null)
    {
        Response.StatusCode = 404;
        Response.Write("Not Found");
        Response.End();
        return;
    }

    List<Thumbnail> thumbnails = Session["file_info"] as List<Thumbnail>;

    if (thumbnails == null)
    {
        Response.StatusCode = 404;
        Response.Write("Not Found");
        Response.End();
        return;
    }

    foreach (Thumbnail thumb in thumbnails)
    {
        if (thumb.ID == id)
        {
            Response.ContentType = "image/jpeg";
            Response.BinaryWrite(thumb.Data);
            Response.End();
            return;
        }
    }

    // If we reach here then we didn't find the file id so return 404
    Response.StatusCode = 404;
    Response.Write("Not Found");
    Response.End();
%>